package com.hbjycl.dao.impl;


import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hbjycl.dao.TreeDao;
import com.hbjycl.entity.Student;
import com.hbjycl.entity.Tree;



@Repository
@Transactional
public class TreeDaoImpl extends BaseDaoImpl<Tree, String> implements TreeDao
{
    @Override
    public boolean isExistByTid(String tid)
    {
        String hql = "from Tree tree where  tree.tid  = ?";
        Tree tree = (Tree) getSession().createQuery(hql).setParameter(0, tid)
                .uniqueResult();
        if (tree != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    @Override
    public Tree getTreeByTid(String tid)
    {
        String hql = "from Tree tree where tree.tid = ?";
        return (Tree) getSession().createQuery(hql).setParameter(0, tid).uniqueResult();
    }
    
    @Override
    public Tree getTreeByPid(String pid)
    {
        String hql = "from Tree tree where tree.pid = ?";
        return (Tree) getSession().createQuery(hql).setParameter(0, pid).uniqueResult();
    }
    
    @SuppressWarnings("unchecked")
	@Override
    public List<Tree> getTreeByTidPnameName(String tid,String pname,String name)
    {
    	String hql = "from Tree tree where tree.tid = '"+tid+"' or tree.pname ='"+pname+"'  or tree.name ='"+name+"'";
    	return (List<Tree>) getSession().createQuery(hql).list();
    }

}
